//
//  CheckScaleViewController.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/8/21.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "CheckScaleViewController.h"
#import "CheckScaleTableViewCell.h"
#import "OrderApi.h"
#import "GaugeResultViewController.h"
@interface CheckScaleViewController ()

@end

@implementation CheckScaleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"测试量表";
    [self loadData];
    [self.tableView registerCellWithNib:@"CheckScaleTableViewCell"];
    // Do any additional setup after loading the view.
}

-(void)loadData
{
    WeakSelf(self)
    OrderApi *api = [[OrderApi alloc]initRequestGaugeList:self.orderService.id];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        if (kCode(request.responseJSONObject)) {
            [weakself.dataArray removeAllObjects];
            
            NSArray *arr = [request.responseJSONObject objectForKey:@"data"];
            
            for (NSDictionary *dic in arr) {
                WKScale *scale = [[WKScale alloc]init];
                [scale setValuesForKeysWithDictionary:dic];
                [weakself.dataArray addObject:scale];
            }
            [weakself.tableView reloadData];
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CheckScaleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CheckScaleTableViewCell" forIndexPath:indexPath];
    WKScale *obj = self.dataArray[indexPath.row];
    WeakSelf(obj)
    cell.title.text = obj.title;
    if (obj.is_test) {
        [cell.btn setTitle:@"查看测试" forState:(UIControlStateNormal)];
    }else{
        [cell.btn setTitle:@"正在测试" forState:(UIControlStateNormal)];
    }
    cell.action = ^(id obj) {
        if (weakobj.is_test) {
        
        }else{
            
        }
    };
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 115;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WKScale *obj = self.dataArray[indexPath.row];
    if (obj.is_test) {
        GaugeResultParam *param = [GaugeResultParam new];
        param.serverId = _orderService.id;
        param.userId = _orderService.user_id;
        param.gaugeId = obj.gauge_test_log_id;
        param.type = GaugeResultBeforeTreat;
        
        GaugeResultViewController *vc = [GaugeResultViewController new];
        vc.param = param;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
